(function($, doc) {
	var user = app.getState();
	var uid = user.user_id;

	var initObj = {
		el: "#app",
		data: {
			dataArr: [],
			isActive: null,
			cartUrl: '',
			postData: {
				uid: '',
				proid: '',
				game_userid: '',
				gasCardTel: '',
				totleMoney: 0,
				cvels: 0,
				code: 0,
				payHash: '',
				payPassword: ''
			},
			fullbox: false,
			moneytitle: ''
		},
		mounted: function() {
			var _this = this;
			_this.$nextTick(function() {
				_this.viewCick();
			});

		},
		methods: {
			viewCick: function() {
				var _this = this;

				//获取油卡列表，不需要传参数
				_this.$http.get(_this.cartUrl + 'BuyApi/getPetrol.html', {
					"id": 123
				}).then(function(res) {
					if(res.body.error === 1) {

						_this.dataArr = res.body.data;
						_this.moneytitle = res.body.moneyTitle;

					}
				});
			},
			clickBut: function(item, index) {
				var _this = this;
				_this.isActive = item;
				_this.postData.totleMoney = item.money;
				_this.postData.cvels = item.cvel;
				_this.postData.proid = item.cid;
			},

			gobuy: function() {
				var _this = this;
				var verif = _this.verification();
				if(verif.errors) {
					_this.$http.post(
						_this.cartUrl + 'BuyApi/buyPetrol.html', {
							uid: _this.postData.uid,
							proid: _this.postData.proid,
							game_userid: _this.postData.game_userid,
							gasCardTel: _this.postData.gasCardTel,
							totleMoney: _this.postData.totleMoney,
							cvels: _this.postData.cvels,
							code: _this.postData.code,
							smstype: 5,
							payHash: '',
							paypassword: _this.postData.payPassword
						}, {
							'headers': {
								'Content-Type': 'x-www-form-urlencoded'
							}
						}
					).then(function(res) {
						console.log(JSON.stringify(res.body));
						$.toast("已提交：" + res.body.msg);
					}, function(res) {

					});
				} else {
					mui.alert(verif.msg);
				}
			},
			verification: function() {
				var _this = this;
				var reg_phone = /^1[3|4|5|7|8][0-9]\d{4,8}$/;
				if(_this.postData.proid == '') {
					return {
						errors: false,
						msg: '请选择油卡类型'
					};
				}

				if(!reg_phone.test(_this.postData.gasCardTel)) {
					return {
						errors: false,
						msg: '手机号码格式不正确'
					};
				}
				if(_this.postData.game_userid == '') {
					return {
						errors: false,
						msg: '加油卡卡号不能为空'
					};
				}
				if(_this.postData.payPassword == '') {
					return {
						errors: false,
						msg: '交易密码不能为空'
					};
				}
				if(_this.postData.code == '') {
					return {
						errors: false,
						msg: '短信验证码不能为空'
					};
				}
				return {
					errors: true,
					msg: ''
				};

			}
		}
	};

	// 解决金额有时显示为很长的浮点数的问题
	Vue.filter('int', function(value) {
		return '' + (value | 0);
	});

	var indexApp = new Vue(initObj);

	//Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('meta[name=__hash__]').getAttribute('content');
	Vue.http.options.emulateJSON = true;
	indexApp.cartUrl = appurl;
	indexApp.postData.uid = uid;
	var getCodeBox = document.getElementById('getCode');
	var c1 = 60;
	getCodeBox && getCodeBox.addEventListener('tap', function() {
		//console.log(app.getState().user_id);
		//console.log(appurl + 'ChatApi/getsms');
		mui.post(appurl + 'ChatApi/getsms', {
			u: app.getState().user_id,
			smstype : 5
		}, function(res) {
			console.log(JSON.stringify(res));
			if(res.status == 1) {
				mui.toast('发送短信成功');
			} else {
				mui.toast(res.msg);
				getCodeBox.innerHTML = '获取验证码';
				getCodeBox.removeAttribute('disabled');
				c1 = 60;
				return;
			}
			var code1 = setInterval(function() {
				getCodeBox.innerHTML = c1 + '秒后重新获取';
				c1 = c1 - 1;
				if(c1 >= 0) {
					getCodeBox.setAttribute("disabled", "disabled");
				} else {
					getCodeBox.innerHTML = '获取验证码';
					getCodeBox.removeAttribute('disabled');
					c1 = 60;
					clearInterval(code1);
				}
			}, 1000);
		});
	})
}(mui, document));